#include "framework.h"

HWND btn_exit;

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "Win32-App";

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
	MSG messages;
	HWND hwnd;
	WNDCLASSEX win;

	win.hInstance = hThisInstance;
	win.lpszClassName = szClassName;
	win.lpfnWndProc = WindowProcedure;
	win.style = CS_DBLCLKS;
	win.cbSize = sizeof(WNDCLASSEX);

	win.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	win.hIconSm = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	win.hCursor = LoadCursor(NULL, IDC_ARROW);
	win.lpszMenuName = NULL;
	win.cbClsExtra = 0;
	win.cbWndExtra = 0;
	win.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));                  // 背景颜色
	if (!RegisterClassEx(&win)) {                                        // 注册窗体失败
		printf("对不起，窗体注册失败!\a");
		return 1;
	}
	// 如果注册窗体成功，运行下方代码------------------代码放在下面...
	hwnd = CreateWindowEx(     /* 建立窗体 */
		0,
		szClassName,
		"AF编辑器",                 /* 窗体名称 */
		WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX & ~WS_THICKFRAME,
		40,
		40,
		944,
		675,
		HWND_DESKTOP,
		NULL,
		hThisInstance,
		NULL
	);
	ShowWindow(hwnd, nFunsterStil);

	while(GetMessage(&messages, NULL, 0, 0)) 
	{
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}
	return messages.wParam;
}

LRESULT CALLBACK WindowProcedure(HWND win, UINT message, WPARAM wParam, LPARAM lParam) {
	HDC hDC, memDC;
	PAINTSTRUCT ps;

	switch(message) {
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_CREATE:
			btn_exit = CreateWindow(TEXT("BUTTON"), TEXT("退出"), WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | BS_PUSHBUTTON | WS_BORDER, 100, 60, 60, 45, win, NULL, NULL, NULL);
			break;
		case WM_PAINT:
			hDC = BeginPaint(win, &ps);
			EndPaint(win, &ps);
			break;
		case WM_COMMAND:
			break;
		case WM_CLOSE:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(win, message, wParam, lParam);
	}

	return 0;
}
